package com.dwd.basic.controller;

import com.dwd.basic.utils.AjaxResult;
import com.dwd.basic.utils.FastDfsApiOpr;
import org.apache.commons.io.FilenameUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Description: TODO
 * @Author 汶狄
 * @Date 2021/1/15 18:40
 * @Version 1.0
 */
@RestController
@RequestMapping("/fastdfs")
public class FastDfsController {
    @PostMapping("/upload")
    public AjaxResult upload(MultipartFile file) {
        try {
            String filename = file.getOriginalFilename();
            String name = FilenameUtils.getExtension(filename);
            String upload = FastDfsApiOpr.upload(file.getBytes(), name);
            return AjaxResult.me().setResultObj(upload);
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }
}
